package com.wuhanpe.leafid.logger

import cn.hutool.core.util.StrUtil
import com.p6spy.engine.spy.appender.MessageFormattingStrategy

/**
 * @author zooy
 * @since 2025/9/12-14:35
 */
class P6SpyLogger: MessageFormattingStrategy {

    override fun formatMessage(connectionId: Int, now: String, elapsed: Long, category: String, prepared: String, sql: String?, url: String?): String {
        return if (StrUtil.isNotBlank(sql)) " Consume Time：" + elapsed + " ms " + now + "\n Execute SQL：" + sql!!.replace(
            "[\\s]+".toRegex(),
            " "
        ) + "\n" else ""
    }
}
